<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2023/11/11
  Time: 14:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="jquery.js"></script>
</head>
<body>
<form action="add" method="post">
    <table border="1">
        <tr style="display: none">
            <td><input type="text" name="id"></td>
        </tr>
        <tr>
            <td>器材名称：</td>
            <td><input type="text" name="name" id="name" placeholder="器材名称"></td>
        </tr>
        <tr>
            <td>器材单价：</td>
            <td><input type="text" name="price" id="price" placeholder="器材单价"></td>
        </tr>
        <tr>
            <td>器材数量：</td>
            <td><input type="text" name="count" id="count" placeholder="器材数量"></td>
        </tr>
        <tr>
            <td>器材状态：</td>
            <td>
                <select name="status" id="status">
                    <option value="0" selected>未投入使用</option>
                    <option value="1">已投入使用</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>采购时间：</td>
            <td><input type="datetime-local" name="buyTime" id="buyTime" placeholder="采购时间"></td>
        </tr>
        <tr>
            <td><input type="submit" value="添加"></td>
        </tr>
    </table>
</form>
<script>
    $("form").submit(res => {
        if ($("#name").val() === '') {
            alert("器材名称不能为空！")
            return false;
        }
        if ($("#price").val() === '') {
            alert("器材价格不能为空！")
            return false;
        }
        if ($("#count").val() === '') {
            alert("器材数量不能为空！")
            return false;
        }

        var regPrice = /^[1-9]+.*[0-9]*$/
        if (!regPrice.test($("#price").val()) ) {
            alert("器材价格必须大于0")
            return false;
        }
        var regCount = /^[1-9]+$/
        if (!regCount.test($("#count").val())) {
            alert("器材数量必须大于0")
            return false;
        }
    })
</script>
</body>
</html>
